home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 176-200 / scopedisk180 / arexxtutorial / listenv / listenv.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-19  |  2KB  |  114 lines

  1. /* ListEnv.rexx */
  2.  
  3. /* Written by  Don Meyer  (Stormgate Software).
  4.  * BIX:        donmeyer
  5.  * GEnie:    D.MEYER
  6.  * Plink:    STORMGATE
  7.  *
  8.  * This program released into the Public Domain.
  9.  */
  10.  
  11. /* Modifications by Jeremy Farrance (ETC Software).
  12.  * Plink:    JEREMY
  13.  * 
  14.  * This program remains in the Public Domain.
  15.  * 
  16.  * Bananas
  17.  */
  18.  
  19. /*        Ver.      Date        Who                    Notes
  20.  *        ----    ---------    ---        -----------------------------
  21.  *        0.0        12-Feb-89    DTM        Creation
  22.  *        0.1        19-Mar-89    DTM        Accept a command line env var name.
  23.  *
  24.  *        0.2        17-Apr-89    JRF        General improvements, fixed ENV names
  25.  *                                    with ' ' spaces, added '?' Usage:,
  26.  *                                    added opensupport(), now checks if
  27.  *                                    ENV: assignment exists and added
  28.  *                                    a files listed count, others...
  29.  */
  30.  
  31. signal on BREAK_C
  32.  
  33. if ~show('L',"rexxsupport.library") then do
  34.    if addlib('rexxsupport.library',0,-30,0) then
  35.       say 'added rexxsupport.library'
  36.    else do;
  37.       say 'support library not available'
  38.       exit 10
  39.    end
  40. end
  41.  
  42. if ~showlist('A','ENV') then do
  43.    say 'ENV: not assigned.'
  44.    exit 10
  45. end
  46.  
  47. arg filename
  48.  
  49. if filename == "?" then do
  50.    say 'Usage: ListEnv [Environment variable name]'
  51.    exit 0
  52. end
  53.  
  54. if length(filename) = 1 & datatype(filename,'U') then pattern = filename
  55.  
  56. if filename ~= "" & pattern = 'PATTERN' then do
  57.    call got_one(filename)
  58.    exit 0
  59. end
  60.  
  61. files = showdir( "ENV:", "File", ":" )
  62. count = 0
  63.  
  64.  
  65. do forever
  66.    parse upper var files name ':' files
  67.    if name == '' then leave
  68.  
  69.    if right(name, 5) == ".INFO" then iterate
  70.  
  71.    if pattern ~= 'PATTERN' & left(name,1) ~= pattern then iterate
  72.  
  73.    count = count + got_one(name)
  74. end
  75.  
  76. if count > 0 then say count' files'
  77. else say 'No environment variables found'
  78.  
  79. exit 0
  80.  
  81.  
  82. got_one:    procedure
  83.  
  84. arg name
  85.  
  86. if ~open( src, "ENV:" || name, "Read" ) then do
  87.    say "** Unable to access 'ENV:" || name || "' **"
  88.    return(0)
  89. end
  90.  
  91. value = readln( src )
  92. equals = readch( src, 1 )
  93.  
  94. if ~eof( src ) then value = value || '1B'x || "[33m ...<more>" || '1B'x || "[31m"
  95.  
  96. if length(value) < 50 then equals = " = "
  97. else do
  98.    equals = '1B'x || "[32m =" || '1B'x || "[31m" || '0A'x || "   "
  99.    if length(value) > 69 then
  100.       value = space(left(value,69),0) || '1B'x || "[32m..." || '1B'x || "[31m"
  101. end
  102.  
  103. say left(name,20) || equals || '"' || value || '"'
  104.  
  105. call close(src)
  106. return(1)
  107.  
  108.  
  109. break_c:
  110.  
  111. say "*** Control-C recieved.  Stopped by user. ***"
  112. exit 5
  113.  
  114.